package org.example.springredis.aop;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;


@Aspect
@Component
public class RedisAop {

    @Autowired
    private StringRedisTemplate redisTemplate;


    @Around("execution(* org.example.springredis.RedisController.*(..))")
    public Object fresh(ProceedingJoinPoint pjp) throws Throwable {
        redisTemplate.execute((RedisConnection e) -> {
            e.flushAll();
            System.out.println("------------ start -----------");
            return null;
        });
        Object result = pjp.proceed();

        System.out.println("------------- end ---------------");
        return result;
    }
}
